#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
struct FastMod{ull b,m;FastMod(ull b):b(b),m((ull)((__uint128_t(1)<<64)/b)){}ull operator()(ull a){ull q=(ull)((__uint128_t (m) * a) >> 64);ull r=a-q*b;return r>=b?r-b:r;}}R(2);

const ll N=1e7+5,P=998244353;
ll n,a[N];

namespace Gen{
	ll A,B,C,mod;
	void read(){
		ll i;cin>>n>>a[0]>>A>>B>>C>>mod;R=FastMod(mod);
		for(i=1;i<=n;i++) a[i]=R(R(A*a[i-1])*a[i-1]+B*a[i-1]+C)+1;
		// for(i=1;i<=n;i++) cerr<<a[i]<<' ';cerr<<endl;
	}
}

ll c[N];
bool check(double d){
	double a=0;
	for(ll i=1;i<=n;i++){
		if(c[i]==1) a=1-a;
		else a=1-d-a;
		if(a<0) return 0;
		a=max(0.,2*d-a);
	}
	return 1;
}
void work(){
	Gen::read();
	ll i;
	fill(c+1,c+n+1,0);
	for(i=1;i<=n;i++) c[a[i]]++;
	// for(i=1;i<=n;i++) cerr<<a[i]<<endl;
	int tot=0;for(i=1;i<=n;i++) if(c[i]) c[++tot]=c[i];
	n=tot;
	
	
	// tot=0;
	// for(i=1;i<=n;i++) if(c[i]==1) tot++;
	// cerr<<tot<<' '<<n-tot<<endl;
	
	double l=0,r=1;
	for(int _=1;_<=20;_++){
		double d=(l+r)/2;
		if(check(d)) l=d;else r=d;
	}
	cout<<fixed<<setprecision(6)<<l<<' '<<1<<'\n';
}

int main(){
	// freopen("ex_guess3.in","r",stdin);
	freopen("guess.in","r",stdin);
	freopen("guess.out","w",stdout);
	// freopen("guess.log","w",stderr);
	cin.tie(nullptr)->sync_with_stdio(false);
	int _;cin>>_;while(_--) work();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<"s"<<endl;
	return 0;
}